package com.ht.medicaltreatment.view

import android.content.Context
import android.view.LayoutInflater
import com.google.android.material.chip.Chip
import com.ht.medicaltreatment.R
import kotlinx.android.synthetic.main.dialog_sample_fromat.*

/**
 * 样本规格
 */
class SampleFormalDialog(context: Context):BaseDialog(context,310f) {

    override fun getLayoutRes() = R.layout.dialog_sample_fromat

    private var H = ""
    private var L = ""

    fun show(onClick:(String,String)->Unit) {
        super.show()
        for (i in 1..10){
            val viewL =
                LayoutInflater.from(context).inflate(R.layout.include_chip, null, false) as Chip
            val viewH =
                LayoutInflater.from(context).inflate(R.layout.include_chip, null, false) as Chip
            viewL.setText("$i 列")
            viewH.setText("$i 行")
            chipGroupL.addView(viewL)
            chipGroupH.addView(viewH)
        }
        chipGroupH.setOnCheckedChangeListener { group, checkedId ->
            val chip = group.findViewById<Chip>(checkedId)
            H = chip.text.split(" ")[0]
        }
        chipGroupL.setOnCheckedChangeListener { group, checkedId ->
            val chip = group.findViewById<Chip>(checkedId)
            L = chip.text.split(" ")[0]
        }
        tvPositive.setOnClickListener {
            if(H.isEmpty() || L.isEmpty() || H == "-1" || L == "-1"){
                return@setOnClickListener
            }
            onClick(H,L)
            dismiss()
        }
    }
}